//
//  AppDelegate+JPush.m
//  DoulinClient
//
//  Created by YLKJ on 2019/2/25.
//

#import "AppDelegate+JPush.h"
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
//#import <UserNotifications/UserNotifications.h>
#endif

@implementation AppDelegate (JPush)
//- (void)cfgJPush:(NSDictionary *)launchOptions {
//    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
//    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
//    //初始化JPush
//    [JPUSHService setupWithOption:launchOptions appKey:@"90186676527e64bad397d918" channel:@"APP" apsForProduction:!kDebug advertisingIdentifier:nil];
//    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
//        //获取registrationID
//        if(resCode == 0){
//            NSLog(@"<-- %s, %d --> registrationID获取成功:%@", __FUNCTION__, __LINE__, registrationID);
//        } else {
//            NSLog(@"<-- %s, %d --> registrationID获取失败, code: %d", __FUNCTION__, __LINE__, resCode);
//        }
//    }];
//}
//- (void)jpushApplication:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//    NSLog(@"<-- %s, %d --> 远程通知 token:%@", __FUNCTION__, __LINE__, deviceToken);
//    NSLog(@"<-- %s, %d --> 极光推送标识此设备的 ID:%@", __FUNCTION__, __LINE__, [JPUSHService registrationID]);
//    [JPUSHService registerDeviceToken:deviceToken];
//}
//- (void)jpushApplication:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//    NSLog(@"<-- %s, %d --> 远程通知注册失败:%@", __FUNCTION__, __LINE__, error);
//}
//// iOS7+ 在前台/后台都会调用此方法
//- (void)jpushApplication:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//    NSLog(@"<-- %s, %d --> 收到远程通知:%@", __FUNCTION__, __LINE__, userInfo);
//    [JPUSHService handleRemoteNotification:userInfo];
//    [[NSNotificationCenter defaultCenter] postNotificationName:PushNotificationReport object:userInfo];
//    NSLog(@"iOS7及以上系统，收到通知:%@", userInfo);
////    [self addOperation:userInfo];
//    completionHandler(UIBackgroundFetchResultNewData);
//}
//// iOS 10 Support 前台得到的的通知对象
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
//    NSDictionary * userInfo = notification.request.content.userInfo;
//    NSLog(@"<-- %s, %d --> 收到远程通知:%@", __FUNCTION__, __LINE__, userInfo);
//    if ([notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]){
//        [JPUSHService handleRemoteNotification:userInfo];
//    }
//    NSDictionary  *   dic = userInfo[@"aps"];
//    NSDictionary  * alert = dic[@"alert"];
//    NSString  *   body = alert[@"body"];
//    [self playVoiceWithContent:body];
//    completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
//}
//// iOS 10 Support 后台得到的的通知对象(当用户点击通知栏的时候)
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
//    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
//    NSDictionary * userInfo = response.notification.request.content.userInfo;
//    NSLog(@"<-- %s, %d --> 收到远程通知:%@", __FUNCTION__, __LINE__, userInfo);
//    if ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//        [JPUSHService handleRemoteNotification:userInfo];
//    }
//    NSDictionary *dic = userInfo[@"aps"];
//    NSDictionary *alert = dic[@"alert"];
//    NSString *body = alert[@"body"];
//    [self playVoiceWithContent:body];
//    completionHandler();//系统要求执行这个方法
//}
//
//#ifdef __IPHONE_12_0
////- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {
////    NSString *title = nil;
////    if (notification) {
////        title = @"从通知界面直接进入应用";
////    } else {
////        title = @"从系统设置界面进入应用";
////    }
////    if (notification && [notification.request.trigger isKindOfClass:UNPushNotificationTrigger.class]) {
////        //从通知界面直接进入应用
////      //  [JPUSHService handleRemoteNotification:userInfo];
////    } else {
////        //从通知设置界面进入应用
////       // [JPUSHService handleRemoteNotification:userInfo];
////    }
//  //  [self handleUserInfo:userInfo];
////}
//#endif
////- (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info {
////    ;
////}
//
//- (void)checkNotification{
//    if (kSysVer >= 10) {
//        UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
//        [center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
//            UNNotification * tmpNoti;
//            for (UNNotification * noti in notifications) {
//                //NSLog(@"<-- %s, %d -->  %f", __FUNCTION__, __LINE__, [noti.date timeIntervalSince1970]);
//                //NSLog(@"<-- %s, %d -->  %@", __FUNCTION__, __LINE__, noti.request.identifier);
//                //NSLog(@"<-- %s, %d -->  %@", __FUNCTION__, __LINE__, noti.request.content.userInfo);
//                NSDictionary * userInfo = noti.request.content.userInfo;
//                if ([userInfo[@"pushType"] intValue] == 1) {
//                    if ((tmpNoti == nil) || ([tmpNoti.date timeIntervalSince1970] < [noti.date timeIntervalSince1970])) {
//                        tmpNoti = noti;
//                    }
//                    //从通知中心删除这条消息
//                    [center removeDeliveredNotificationsWithIdentifiers:@[tmpNoti.request.identifier]];
//                }
//            }
//            dispatch_async(dispatch_get_main_queue(), ^{
//                [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
//            });
//        }];
//    }
//}
//#pragma mark iOS12.1以下 播放语音
//
//- (void)playVoiceWithContent:(NSString *)content {
//
//    AVSpeechSynthesizer * synthsizer = [[AVSpeechSynthesizer alloc] init];
//    synthsizer.delegate = self;
//    AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString:content];//需要转换的文本
//    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];//国家语言
//    utterance.rate = 0.5f;//声速
//    utterance.volume = 1;
//    [synthsizer speakUtterance:utterance];
//}
//
////新增语音播放代理 语音播放完成的代理函数中添加播完弹框功能
//- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
//  //  self.contentHandler(self.bestAttemptContent);
//}

@end
